package algorithm;

import java.util.HashMap;
import java.util.Map;

public class User_level {
	public Map<String,Integer> Get_user_level(double experience,int now_level){
		Map<String,Integer> map = new HashMap<String,Integer>();
		int user_level = 5;   //设置初始用户等级5
		int flag = 0;         //用户等级是否改变的标识符
		if(experience <= 10){
			user_level = 1;
		}
		else if(experience <= 250){
			user_level = (int) Math.floor(  Math.sqrt(experience / 10) );
		}
		else{
			while(10 * (user_level * user_level - user_level + 5) < experience){
				user_level++;
			}
			user_level--;
		}
		
		if(now_level == user_level)
			flag = 0;  //若等级不变，flag = 0
		else 
			flag = 1;  //等级变化。flag = 1
		map.put("user_level", user_level);  //现在的等级
		map.put("flag", flag);              //是否变化
		return map;
	}
}
